<?php

/**
 * 邮费计算
 * @author 戚银
 * @email thinkercode@sina.com
 * @date 2015年8月27日 下午6:02:49
 */
class PostageApp extends MallbaseApp
{

    /**
     * 计算可用邮费列表
     * @author jyx
     * @date 2015/09/17
     */
    public function index()
    {
        $action = '计算可用邮费列表';
        setLogParameter($action);
        $this->check_method('GET');
        $good_id = $this->get_gp('good_id', 'G');
        $quantity = $this->get_gp('quantity', 'G');
        $region_id = $this->get_gp('region_id', 'G');
        if (empty($good_id) || empty($quantity) || empty($region_id)) {
            $this->ajax_return(FLAG_ERROR, '非法操作！');
        }

        $model = m('postal');
        $model->addinfo($region_id);
        $model->addgoods($good_id, $quantity);
        $list = $model->expresslist();

        if (empty($list) || $model->error) {
            $this->ajax_return(FLAG_ERROR, $model->error);
        }

        $data = array();
        asort($list);
        foreach ($list as $key => $val) {
            $data[] = array(
                'name' => $key,
                'price' => $val
            );
        }
        $this->ajax_return(FLAG_OK, '', $data);
    }
}